//
//  AboutUsViewController.m
//  PigMarket
//
//  Created by mac on 2019/3/23.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AboutUsViewController.h"
#import "SystemSetingCell.h"

@interface AboutUsViewController ()

/**
 dataArr
 */
@property (nonatomic , strong) NSArray *dataArr;

/**
 allRightLab
 */
@property (nonatomic , strong) UILabel *allRightLab;

@end

@implementation AboutUsViewController


#pragma mark - view life cycle

- (void)setupUI{
    
    self.baseNavView.navTitleLabel.text = @"关于我们";
    self.tableView.separatorColor = mIconLineColor;
    self.tableView.bounces = NO;
    [self.view addSubview:self.allRightLab];
    
}

- (void)setupLayout{
    
    self.tableView.rowHeight = 54.f;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(TJ_NavBarHeight);
        make.right.left.bottom.mas_equalTo(self.view);
    }];
    [self.allRightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.tableView.mas_centerX);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-IPHONEXBottomEdge);
    }];
}

- (void)initData {
    self.dataArr = @[@{@"title":@"用户协议",@"detail":@""},
                     @{@"title":@"隐私政策",@"detail":@""},
                     @{@"title":@"免责声明",@"detail":@""},
                     @{@"title":@"激励政策",@"detail":@""},
                     @{@"title":@"版本更新",@"detail":@"已是最新版本"}];
}

#pragma mark - delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 220;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    
    
    UIView *headerView = [self addTableViewSectionSegmentationLineByY: 219.5];
    
    UIImageView *logoImgView = [[UIImageView alloc] init];
    logoImgView.image = [UIImage imageNamed:@"login_logo"];
    [headerView addSubview:logoImgView];
    [logoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(48);
        make.centerX.mas_equalTo(headerView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(80, 80));
    }];
    UILabel *appNameLab = [[UILabel alloc] init];
    appNameLab.text = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    appNameLab.textColor = [UIColor textBlackColor];
    [headerView addSubview:appNameLab];
    [appNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(headerView.mas_centerX);
        make.top.mas_equalTo(logoImgView.mas_bottom).offset(14);
        make.height.mas_equalTo(24);
    }];
    UILabel *versionLab = [[UILabel alloc] init];
    versionLab.textColor = [UIColor colorWithHexString:@"#999999"];
    versionLab.font = [UIFont largerFont];
    versionLab.text = [NSString stringWithFormat:@"V%@",[infoDictionary objectForKey:@"CFBundleShortVersionString"]];
    [headerView addSubview:versionLab];
    [versionLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(headerView.mas_centerX);
        make.top.mas_equalTo(appNameLab.mas_bottom).offset(12);
        make.height.mas_equalTo(24);
    }];
    return headerView;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SystemSetingCell *cell = [SystemSetingCell cellWithTableView:tableView];
    cell.infoDic = self.dataArr[indexPath.row];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}


#pragma mark - getter and setter

- (void)registerTableViewCell{
    
    self.tableView.mj_footer.hidden = YES;
    self.tableView.mj_header.hidden = YES;
}


- (NSArray *)dataArr {
    
    if (!_dataArr) {
        _dataArr = [[NSArray alloc] init];
    }
    return _dataArr;
}


- (UILabel *)allRightLab {
    
    if (!_allRightLab) {
        _allRightLab = [[UILabel alloc] init];
        _allRightLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _allRightLab.font = [UIFont smallFont];
        _allRightLab.text = @"自然生长公司   版权所有 \nCopyright @2018-2022 Tunji All Rights Reserved";
        _allRightLab.numberOfLines = 0;
        _allRightLab.textAlignment = NSTextAlignmentCenter;
    }
    return _allRightLab;
}
@end
